<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="" prop="key">
        <el-input
          v-model="queryParams.procDefKey"
          placeholder="请选择流程定义"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="name">
        <el-input
          v-model="queryParams.keyword"
          placeholder="支持标题或类别查询"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-divider direction="vertical"></el-divider>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <!--<el-table-column type="selection" align="left" width="55" />-->
      <el-table-column label="实例id" align="left" prop="processInstanceId" width="150" />
      <el-table-column label="标题" align="left" prop="processInstanceName" width="300" />
      <!--<el-table-column label="业务分类" align="left" prop="name" width="150" />-->
      <el-table-column label="流程定义名" align="left" prop="processDefinitionName" width="180" />
      <el-table-column label="流程定义id" align="left" prop="processDefinitionId" width="180" />
      <el-table-column label="发起人" align="left" prop="startUserNickName" width="120" />
      <el-table-column label="发起时间" align="left" prop="startTime" width="180" />
      <el-table-column label="状态" align="left" prop="state" width="300" />
      <el-table-column label="操作" align="left" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-picture"
            @click="handleDiagram(scope.row)"
          >查看流程图</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleShowForm(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="流程图查看" :visible.sync="diagram.show" width="1000px" append-to-body>
      <div style="width: 100%; text-align: center;">
        <el-image
          :src="diagram.src"
          :preview-src-list="diagram.srcList"
        />
      </div>
      <div style="text-align: center; color: #909399; margin-top: 20px;">* 绿色表示已执行，红色表示当前待执行</div>
      <div slot="footer" class="dialog-footer" style="text-align: right;">
        <el-button @click="close">关闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import { listData } from "@/api/activiti/instance.js"
  import { format } from "@/utils/activiti/myUtil.js"

  export default {
      name: "Instance",
      data() {
          return {
              loading: true,// 遮罩层
              diagram: {//流程图查看框
                  show: false,
                  src: null,
                  srcList: [],
              },
              queryParams: {// 查询参数
                  pageNum: 1,
                  pageSize: 10,
                  procDefKey: undefined,
                  keyword: undefined,
              },
              ids: [],// 选中数组
              total: 0,// 总条数
              dataList: [],//列表数据
          };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询流数据列表 */
      getList() {
        this.loading = true;
          listData(this.queryParams).then(
          response => {
              this.dataList = response.rows;
              this.total = response.total;
              this.loading = false;
          }
        );
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
        /** 流程图 */
        handleDiagram: function(row) {
            this.diagram.src = process.env.VUE_APP_BASE_API+'/activiti/activiti/process/diagram/inst/' + row.processInstanceId;
            this.diagram.srcList.push(this.src);
            this.diagram.show = true;
        },
        close: function(){
            this.diagram.show = false;
        },
        /** 跳转页面 */
        handleShowForm(row) {
            this.$router.push("/openform/view/" + row.deploymentId + "/" + row.processDefinitionId.replace(/:/g,"_") + "/" + row.processInstanceId);
        },
    },
  }
</script>

<style scoped>

</style>
